<html>
<head>
<title>DIGI-Infomat</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link href="style.css" rel="stylesheet" type="text/css">
	<style type="text/css">
		.style1
		{ width: 20%;}
	</style>

<script type="text/javascript">
function addRow ()  /*{{{*/
{
	var i = idRoutineListTable.rows.length; 
	var newRow = idRoutineListTable.insertRow(-1);
	if (i%2!=0) {
		newRow.className="routineListCell";
	}
	var newColumn1 = newRow.insertCell(-1);
	newColumn1.style.borderWidth=1 ;
	newColumn1.innerHTML = i;
	
	var newColumn2 = newRow.insertCell(-1);
	newColumn2.style.borderWidth=1 ;
	newColumn2.innerHTML = '----';
	
	var newColumn3 = newRow.insertCell(-1);
	newColumn3.style.borderWidth=1 ;
	newColumn3.innerHTML = '----';
	
	var newColumn4 = newRow.insertCell(-1);
	newColumn4.style.borderWidth=1 ;
//	newColumn4.innerHTML = '<input type="button" value="E" onclick=javascript:location.href="editlist.php?id='+i+';"></input>';
	newColumn4.innerHTML = '<input type="button" value="E" onclick=javascript:location.href="editlist.php?"></input>';
	
	var newColumn5 = newRow.insertCell(-1);
	newColumn5.style.borderWidth=1 ;
	newColumn5.style.textAlign="center";
	newColumn5.innerHTML = '<input type="text" size="2" maxlength="2" id="idTimeoutText" value="10"></input>';
	
	var newColumn6 = newRow.insertCell(-1);
	newColumn6.style.borderWidth=1 ;
	newColumn6.innerHTML = '<input type="checkbox" id="idCheckBox" onClick="GetRow()"/><input type="hidden" name="nameCheckBox" id='+i+' />'; 
} /*}}}*/

function GetRow()  /*{{{*/
{
	cGetRow=window.event.srcElement.parentElement.parentElement.rowIndex; 
}  /*}}}*/

function deleteRow()  /*{{{*/
{
	var checked=0;
	var checkboxAll=document.all("idCheckBox");
	for(var i=0;i<checkboxAll.length;i++) {
		if (checkboxAll[i].checked==true) {
			checked++;
		}
	}
	if(checked==0) {
		alert('Please select the item you will delete');
		return false;
	} 
	/*{{{*/
	//else { 
	//	for(var a=0;a<checked;a++) {
	//		for(var i=0;i<checkboxAll.length;i++){
	//			if(checkboxAll[i].checked==true) {
	//				idRoutineListTable.deleteRow(i+1);
	//				break;
	//			}
	//		}
	//	}
	//}
	/*}}}*/
}  /*}}}*/

function lastname(upload_name, suffix_check){ /*{{{*/
	var filepath = document.getElementById(upload_name).value; 
	if(filepath=="") {
		alert ('Please Select File');
		return false;
	}
	if (upload_name == 'browse_image') {
		if (0==document.getElementById('div_html_radio_group').hasChildNodes())
		{
			alert ('There is no HTML file in the list, please upload first');
			return false;
		}
	}
	var re = /(\\+)/g; 
	var filename=filepath.replace(re,"#");
	var one=filename.split("#");
	var two=one[one.length-1];
	var three=two.split(".");
	var last=three[three.length-1];
	var rs=suffix_check.indexOf(last);
	if(rs>=0){
		return true;
	}else{
		var err = "please upload "+suffix_check + " file";
		alert(err);
		return false;
	}
} /*}}}*/

</script>
</head>

<?php
/************* PHP Start************/ /*{{{*/
include "xplaylist.php";

$xRoutineList = new XPlayList();

// backup routinelist

if (!empty($_POST)) {	
	//echo "<pre>";  /*{{{*/
	//print_r($_POST);
	//echo "</pre>";  /*}}}*/

	// have to know user press delete button
	if (isset($_POST['btnDelete']))
	{	
		if ($_POST['btnDelete'] == 'delete') {
			$delete_item = array();
			foreach($_POST as $name=>$value)
			{
				$name_list = explode("_", $name);
				if($name_list[0] == "checkbox"){
					$id = $name_list[1];
					//echo $id.'<br>';
					$delete_item[] = $id-1;
				}
				else{
					//do sth else;
				}
			}
			//echo '<pre>';
			//print_r ($delete_item);
			//echo '<pre>';
			$xRoutineList->deleteSpecifiedRecords($delete_item);
			$xRoutineList->saveRoutineIni();
		}
	} else if (isset($_POST['sumbit_reset'])) {
		$xlist->restoreRoutineList();
	}

}
/* **************************** PHP **********************************/ /*}}}*/
?>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="text-align:center">
<table width="100%"> 
<tr>
   <td align="center">
		<table width="780px" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td>
					<table border="0" bgcolor="#FFFFFF" width="100%" cellpadding="0"> <!--/*{{{*/ Navigation-->
						<tr> <td rowspan="2" width="20%"><img src="images/logo.png" alt="logo"></td></tr> 
						<tr valign="bottom"  align="center">
							<td><a href="home.php"><img style="border-width:0px;" src="images/btn_home.png"  alt="HOME"></a></td>
							<td><a href="network.php"><img style="border-width:0px;" src="images/btn_network.png" alt="Network Setting"></a></td>
							<td><a href="update.php"><img style="border-width:0px;" src="images/btn_update.png" alt="Update"></a></td>
							<td><a href="setting.php"><img style="border-width:0px;" src="images/btn_setting.png" alt="setting"></a></td>
							<td><a href="filemanage.php"><img style="border-width:0px;" src="images/btn_filemanage.png" alt="File Manage"></a></td>
							<td><a href="routinelist.php"><img style="border-width:0px;" src="images/btn_playlist.png" alt="File Manage"></a></td>
						</tr>
					</table> <!--/*}}}*/-->
				</td>
			</tr> 
			<tr>
				<td colspan="2">
					<table border="0" cellspacing="0" cellpadding="0"></table> <!-- Interval -->
				</td>
			</tr>
			<tr>
				<td colspan="2" valign="middle" bgcolor="#FFFFFF">
				<form name="form_routinelist" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">   <!-- Todo: remove it -->
					<table border="0" cellspacing="0" cellpadding="0"  width="780px" class="form_table">
						<tr> 
							<td width="3%" >&nbsp;</td>
							<td colspan="4" valign="middle" class="name" style="width:380px;"><strong class="green-text">Routine Play List Setting</strong></td>
						</tr>
						<tr>
						   <td></td>
						   <td colspan="4" valign="middle" class="style1" style="width:140px;">
<?php 
/********* PHP.Start.LoadRoutineContent*********/ /*}}}*/
$xRoutineList->showRoutineListTable();
echo '<br>';
/********* PHP.ENd *****************************/ /*}}}*/
?>
							</td>
						</tr>
						<tr>
						  <td></td>
						  <td valign="middle" style="width:30%"> <input type="submit" value="save"></input></td>
						  <td width="30%" align="center"><input type="submit" value="reset" name="sumbit_reset"></input></td>
						  <!-- <td width="30%" align="center"><input type="button" value="add" onclick="javascript:addRow();"></input></td>	-->
						  <td width="30%" align="center"><input type="button" value="add" onclick=javascript:location.href="editlist.php?id=-1"></input></td>	
						  <td width="30%" align="center"><input type="submit" name="btnDelete" value="delete" onclick="return deleteRow();"></input></td>	
						</tr>
					</table>
				</form> 
				</td>
			</tr>
		<tr>
		<td colspan="4" align="center" class="white-text"> <!-- /*{{{*/ Footer -->
			<table width="100%" border="0" cellspacing="0" cellpadding="10">
			<tr>
			<td align="center" class="white-text">Copyright &copy;  Teraoka Weigh System. All Rights Reserved.</td>
			</tr>
			</table>
		</td> <!--/*}}}*/ -->
		</tr>
	</table>
  </td>
</tr>
</table>
</body>
</html>
